package com.wanxi.servlet.user;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.dto.ResultDto;
import com.wanxi.model.UserModel;
import com.wanxi.service.Impl.UserServiceImpl;
import com.wanxi.service.UserService;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Li
 * @Date 2023/5/5 14:45
 */
@WebServlet("/back/FindUserCount")
public class FindUserCountServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.乱码问题
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //2.接收前端数据

        //3.封装数据

        //4.调用服务逻辑层
        UserService userService = new UserServiceImpl();
        int totalUserCount = userService.totalCount();
        //数据转发给前端：IO流方式
//        数据格式使用JSON对象,引入第三方jar包，fastJson
        resp.getWriter().println(JSONObject.toJSONString(totalUserCount));
    }
}
